import { createRouter, createWebHistory } from 'vue-router'
const requireContext = require.context('./modules', true, /.*\.js/)
const routes = []
requireContext.keys().forEach(key => {
  routes.push(...requireContext(key).default)
})

const ROUTER_BASE_URL = window.__POWERED_BY_QIANKUN__ ? `/micro-storm/` : '/'

const router = createRouter({
  history: createWebHistory(ROUTER_BASE_URL),
  routes,
})

router.beforeEach((to, from, next) => {
  const { title } = to.meta
  document.title = title
  next()
})

// const VueRouterPush = router.push
// router.push = function push(to) {
//   return VueRouterPush.call(this, to).catch(err => err)
// }
export default router
